package pageShare

import (
	"context"
	"encoding/json"

	"laundry-service/app/client/internal/svc"
	"laundry-service/app/client/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeletePageShareLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeletePageShareLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePageShareLogic {
	return &DeletePageShareLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeletePageShareLogic) DeletePageShare(req *types.DeletePageShareRequest) (resp *types.Reply, err error) {

	userId, _ := l.ctx.Value("userId").(json.Number).Int64()
	_, err = l.svcCtx.Db.GetAdminById(int(userId))
	if err != nil {
		return nil, err
	}

	err = l.svcCtx.Db.DeletePageShare(req.Id)
	if err != nil {
		l.Logger.Errorf("delete page share error: %v", err)
		return nil, err
	}

	return nil, nil
}
